<%--
  Created by IntelliJ IDEA.
  User: pc
  Date: 2024/6/28
  Time: 15:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>发布新闻页面</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
</head>
<body>
    <br/><br/><br/>
    <div align="center">
        <form name="addForm">
            <table width="500" border="1" bordercolor="#f00" align="center">
                <tr>
                    <td width="30%" align="center">标题：</td>
                    <td width="70%">
                        <input type="text" name="ntitle" id="ntitle">
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center">内容：</td>
                    <td width="70%">
                        <textarea name="ncontext" maxlength="480" id="ncontext"></textarea>
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center">发布人：</td>
                    <td width="70%">
                        <input type="text" hidden name="uid" id=uid value="${LOGIN_USER.uid}">
                        <input type="text" disabled name="uname" value="${LOGIN_USER.uname}">
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <input type="button" value="发布" onclick="submitNewsinfo()">
                    </td>
                </tr>
            </table>
        </form>
    </div>

<script type="text/javascript">
    function submitNewsinfo() {

        var ntitle = $("#ntitle").val();
        var ncontext = $("#ncontext").val();
        var uid = $("#uid").val();

        $.ajax({
            url: "${pageContext.request.contextPath}/addnewsinfo",
            type: "post",
            data: JSON.stringify({ntitle: ntitle,ncontext: ncontext,uid: uid}),
            contentType: "application/json;charset=utf-8",
            dataType: "json",

            success: function(){
                window.location.href="${pageContext.request.contextPath}/newsinfo"
            },
            error: function () {
                null
            }
        })
    }
</script>
</body>
</html>
